package getools4me;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.PrintStream;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;



public abstract class MyHttpServlet extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = -3310616924160149704L;

	ByteArrayOutputStream baos ;
	PrintStream ps ;
	
	public void myinit() throws ServletException {
		baos = new ByteArrayOutputStream();
		ps = new PrintStream(baos);
		System.setOut(ps);
		System.setErr(ps);
	}
	
	
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		if(baos==null) myinit();
		baos.reset();
		
		doMyPost(req, resp);
		
		resp.getOutputStream().write(baos.toByteArray());
		
	}
	
	protected void doMyPost(HttpServletRequest req, HttpServletResponse resp)
	throws ServletException, IOException {
	}
	
}
